﻿function readCookie(name) {
    var start = document.cookie.indexOf(name);
    return start;
}


function readCookie2(name) {//读取Cookie 
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf("&", offset);
            if (end == -1) end = document.cookie.length;
            //cookieValue = unescape(document.cookie.substring(offset, end)) 
            cookieValue = document.cookie.substring(offset, end)
        }
    }
    return cookieValue;
}

function writeCookie(name, value) {//写入Cookie 
    var expire = "";
    //if(hours != null){ 
    expire = new Date((new Date()).getTime() + 3600000);
    expire = "&expires=" + expire.toGMTString();
    //} 
    document.cookie = name + "=" + value + expire;
}


function escape2(str) {
    return escape(str).replace(/\+/g, "%2b");
}






//验证Cookie 
function ChkCookie() {
    if (readCookie("userid") != "") {
        UserLogin(0);
    }
    else {
        $("#Login")[0].style.display = "block";
    }
}




//无刷新发布评论
function p_report(InfoID) {

    var txt = '骗子信息';

    $.ajax({
        type: "POST",
        url: "../Ajax.aspx@action=PostComment",
        data: "InfoID=" + InfoID + "&Txt=" + escape2(RemoveHTML(txt)),
        success: function (msg) {

          
                alert("您的举报已成功提交！");

      
        }
    });
}





//无刷新发布评论
function p_comment(InfoID) {

    var txt = $("comment_txt").value;
    if (!txt) { alert("请填写评论内容！"); return; }
    if (txt.length < 3) { alert("评论内容不能少于3个字符！"); return; }
    var option = {
    parameters: "InfoID=" + InfoID + "&Txt=" + escape2(RemoveHTML(txt)),
        method: "post",
        onSuccess: function(transport) {
            var rp = transport.responseText;
            //            if (rp == "OK") {
            //                var temp = "";

            //                $("comment_post").innerHTML = temp;
            alert("您的回复已成功提交！");
            //                $("comment_quick").style.display = "block";
            //                $("comment_quick").innerHTML = "<div class=\"t\"><a href=\"" + BookID + "\">" + BookID + "</a> 发布于 <span>" + DateDemo() + "</span></div><div>" + txt + "</div><div class=\"reply\"><a href=\"javascript:PostReply('" + BookID + "')\">回复</a></div>";
            $("comment_list").innerHTML = rp;
            $("comment_txt").value = "";
            var tempNum = parseInt($("C_Num").innerHTML);
            $("C_Num").innerHTML = tempNum + 1;
            //            }
            //            else {
            //                alert("操作失败！");
            //            }
        },
        onFailure: function(transport) {
            alert("数据提交失败，请检查网络或重试。");
        }
    }
    var request = new Ajax.Request("../Ajax.aspx@action=PostComment", option);
    return;
}



function UserLogin2() {
    var uName = $("#Login_User")[0].value;
    var uPass = $("#Login_Pwd")[0].value;
    var uExpires = 0;
    if (!uName || !uPass) return;
    if (document.getElementsByName("Login_Exp").checked = true) {
        uExpires = 3650000;
    }
    $("#EnterOper")[0].disabled = true;


    $.ajax({
        type: "POST",
        url: "../Ajax.aspx@action=UserLogin2",
        data: "User=" + escape2(uName) + "&Pass=" + escape2(uPass) + "&Expires=" + escape2(uExpires),
        success: function (msg) {
            if (msg == "Login") {
                var pos, str, para, parastr;
                str = window.location.href;
                pos = str.indexOf("=")
                parastr = str.substring(pos + 1);
                if (pos > 0) {
                    parent.location = parastr;
                }
                else {
                    parent.location = '../';
                }
            }
            else {
                $("#Login_Text")[0].innerHTML = "账号或密码错误！";
                $("#EnterOper")[0].disabled = false;
            }
        }
    });






}


    //XmlHttp无刷新登陆
function UserLogin(s) {
        //参数说明:s=0,1,2分别指"判断状态","登陆","退出"

        $.ajax({
            type: "POST",
            url: "../Ajax.aspx@action=UserLogin",
            data: "State=" + s,
            success: function (msg) {
                if (msg == "LoginOut") {
                    $("#LoginSuc")[0].style.display = "none";
                    $("#Login")[0].style.display = "block";
                    $("#LoginBtn")[0].disabled = false;
                    $("#txtPass")[0].value = "";
                }
                    //			    else if(rp.indexOf("error=")>-1)
                else if (msg == "nologin") {
                    $("#Login")[0].style.display = "block";

                }
                else if (msg != "") {
                    $("#LoginSuc")[0].innerHTML = msg;
                    $("#Login")[0].style.display = "none";
                    $("#LoginSuc")[0].style.display = "block";
                }
            }
        });

    }



function post_now() {
        var chk = true
        if (!Chk_Post2()) { chk = false }
        if (chk) {
            $("regbotton").disabled = true;
            var ITitlegt2 = $("Titlegt2").value;
            var IUser = $("UserName").value;
            var IPrice = $("Price").value;
            var ICode = $("Code").value;
            var IBID = $("BID").value;
            var ISID = $("SID").value;
            var IType = $("Type").value;
            var ITerm = $("Term").value;
            var IPic = $("Pic").value;
            var IAdd = $("Address").value;
            var ITel = $("Tel").value;
            var IWeb = $("Web").value;
            var IQQ = $("QQ").value;
            var IFax = $("Fax").value;
            var IEmail = $("Email").value;
            var IContent = $("Content").value;
            var IArea = $("Area").value;


            var option = {
                parameters: "Titlegt2=" + escape2(ITitlegt2) + "&Code=" + escape2(ICode) + "&UserName=" + escape2(IUser) + "&Price=" + escape2(IPrice) + "&BID=" + escape2(IBID) + "&SID=" + escape2(ISID) + "&Type=" + escape2(IType) + "&Term=" + escape2(ITerm) + "&Pic=" + escape2(IPic) + "&Address=" + escape2(IAdd) + "&Tel=" + escape2(ITel) + "&Web=" + escape2(IWeb) + "&QQ=" + escape2(IQQ) + "&Fax=" + escape2(IFax) + "&IEmail=" + escape2(Email) + "&Content=" + escape2(IContent) + "&Area=" + escape2(IArea),
                method: "post",
                onSuccess: function (transport) {
                    var rp = transport.responseText;
                    if (rp == "OK") {
                        alert('信息发布成功，请等待审核后才能看到您发布的内容！'); parent.location = 'List.aspx'
                    }
                    else {
                        alert(rp);
                    }
                    $('regbotton').disabled = false;
                },
                onFailure: function (transport) {
                    alert("数据提交失败，请检查网络或重试。");
                }
            }
            var request = new Ajax.Request("Ajax.aspx@action=PostNows", option);
            return;
        }
    }

